package top.loonglove.newindexserver.service.common.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import top.loonglove.common.base.result.PageResult;
import top.loonglove.newindexserver.bo.common.query.AccountPageQuery;
import top.loonglove.newindexserver.bo.common.query.AccountQuery;
import top.loonglove.newindexserver.dao.common.AccountDao;
import top.loonglove.newindexserver.entity.Account;
import top.loonglove.newindexserver.service.common.AccountService;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2021/7/28 3:04
 */
@Service
public class AccountServiceImpl implements AccountService {

    private final AccountDao accountDao;

    @Autowired
    public AccountServiceImpl(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    /**
     * Locates the user based on the username. In the actual implementation, the search
     * may possibly be case sensitive, or case insensitive depending on how the
     * implementation instance is configured. In this case, the <code>UserDetails</code>
     * object that comes back may have a username that is of a different case than what
     * was actually requested..
     *
     * @param username the username identifying the user whose data is required.
     * @return a fully populated user record (never <code>null</code>)
     * @throws UsernameNotFoundException if the user could not be found or the user has no
     *                                   GrantedAuthority
     */
    @Override
    public Account loadUserByUsername(String username) throws UsernameNotFoundException {
        return accountDao.loadUserByUsername(username);
    }

    /**
     * 添加数据
     *
     * @param account 数据
     */
    @Override
    public void add(Account account) {
        accountDao.add(account);
    }

    /**
     * 删除数据，假删除
     *
     * @param account 数据
     */
    @Override
    public void remove(Account account) {
        accountDao.remove(account);
    }

    /**
     * 获取数据
     *
     * @param account 查询项
     * @return 数据
     */
    @Override
    public Account get(AccountQuery account) {
        return accountDao.get(account);
    }

    /**
     * 分页获取查询项
     *
     * @param q extend BasePageQuery
     * @return 分页查询结果
     */
    @Override
    public PageResult<Account> getPage(AccountPageQuery q) {
        return accountDao.getPage(q);
    }

    /**
     * 修改数据
     *
     * @param account 新数据
     */
    @Override
    public void modify(Account account) {
        accountDao.modify(account);
    }

    /**
     * 删除数据，真删除
     *
     * @param account 删除数据
     */
    @Override
    public void delete(Account account) {
        accountDao.delete(account);
    }
}
